﻿using System;
using System.Collections.Generic;
using System.Xml;
using Assist;
using Autodesk.Revit.DB;

namespace HYOpeningCommon.OpeningProfile
{
	public class OpeningProfileCircle : OpeningProfileBase
	{
		public override string GetCutSize(bool bIsFeet)
		{
			double num = this.m_dCutDiameter;
			if (!bIsFeet)
			{
				num = AssistFunc.feetToMM(this.m_dCutDiameter);
			}
			return num.ToString("f0");
		}

		public override string GetOpeningSize(bool bIsFeet)
		{
			double val = this.m_dCutDiameter + this.m_dExtendDist * 2.0;
			if (!bIsFeet)
			{
				val = AssistFunc.feetToMM(val);
			}
			return val.ToString("f0");
		}

		public override bool Export2XmlNode(XmlElement xmlNode)
		{
			try
			{
				if (!base.Export2XmlNode(xmlNode))
				{
					return false;
				}
				xmlNode.SetAttribute("CutDiameter", this.m_dCutDiameter.ToString());
			}
			catch
			{
				return false;
			}
			return true;
		}

		public override bool ImportByXmlNode(XmlNode xmlNode)
		{
			try
			{
				if (!base.ImportByXmlNode(xmlNode))
				{
					return false;
				}
				this.m_dCutDiameter = Convert.ToDouble(xmlNode.Attributes["CutDiameter"].Value);
			}
			catch
			{
				return false;
			}
			return true;
		}

		public override Outline GetSectionOutline3D()
		{
			return base.GetSectionOutline3D();
		}

		public override void GetProfileOutLineOnXOY(ref List<XYZ> lstPreviewPt, bool isAddExtend)
		{
			XYZ xyz = new XYZ(0.0, 0.0, 0.0);
			XYZ xyz2 = xyz + this.m_dCutDiameter / 2.0 * XYZ.BasisY.Negate() + XYZ.BasisX.Negate() * this.m_dCutDiameter / 2.0;
			XYZ xyz3 = xyz2 + XYZ.BasisX * this.m_dCutDiameter;
			if (isAddExtend)
			{
				double num = this.m_dTolerance + this.m_dExtendDist;
				xyz2 += num * XYZ.BasisY.Negate() + num * XYZ.BasisX.Negate();
				xyz3 += num * XYZ.BasisY.Negate() + num * XYZ.BasisX;
			}
			XYZ item = 2.0 * xyz - xyz3;
			XYZ item2 = 2.0 * xyz - xyz2;
			lstPreviewPt.Add(xyz2);
			lstPreviewPt.Add(xyz3);
			lstPreviewPt.Add(item2);
			lstPreviewPt.Add(item);
		}

		public double m_dCutDiameter;
	}
}
